package action;

import impl.TBookDAOimpl;
import impl.UserDAOimpl;

import java.sql.SQLException;
import java.util.List;

import javax.security.auth.message.callback.PrivateKeyCallback.Request;

import model.TBook;
import DAO.TBookDAO;

import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionSupport;

public class login extends BaseAction {
private int userid;
private String pwd;
private TBook tBook;

	public TBook gettBook() {
	return tBook;
}

public void settBook(TBook tBook) {
	this.tBook = tBook;
}

	public int getUserid() {
	return userid;
}

public void setUserid(int userid) {
	this.userid = userid;
}

public String getPwd() {
	return pwd;
}

public void setPwd(String pwd) {
	this.pwd = pwd;
}

	/**
	 * @return
	 */
	public String execute() {
		UserDAOimpl us=new UserDAOimpl();
		TBookDAO tb=new TBookDAOimpl();
			try {
			List<TBook> list = us.logintUser(userid, pwd, null);
			
			String json1=JSON.toJSONString(list);
			
		
		
			List<TBook> list1 = tb.selecTBooks();
			if (list.size()!=0) {
				String json=JSON.toJSONString(list1);
				request.getSession().setAttribute("json", json);
			
				return SUCCESS;
			}else {
			
				return ERROR;	
			}
			
			} catch (SQLException e) {
				
				e.printStackTrace();
				return ERROR;
			}
			
			
		
		
		
	}
}